<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="virtualfooddrive-inf.com.Donation">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
			select 	ID, USER_ID, AMOUNT, DONATION_DATE, FOODDRIVE_ID, PAYMENT_CONFIRM_CODE, 
					PAYMENT_CONFIRMED, TRANSACTION_ID
			from dbo.DONATIONS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "virtualfooddrive-inf.com.Donation").init();
			obj.setID(qRead.ID);
			obj.setUSER_ID(qRead.USER_ID);
			obj.setAMOUNT(qRead.AMOUNT);
			obj.setDONATION_DATE(qRead.DONATION_DATE);
			obj.setFOODDRIVE_ID(qRead.FOODDRIVE_ID);
			obj.setPAYMENT_CONFIRM_CODE(qRead.PAYMENT_CONFIRM_CODE);
			obj.setPAYMENT_CONFIRMED(qRead.PAYMENT_CONFIRMED);
			obj.setTRANSACTION_ID(qRead.TRANSACTION_ID);
			return obj;
		</cfscript>
	</cffunction>

	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.Donation">
		<cfset var qCreate="">

		<cfset var qGetId="">

		<cfset var local1=arguments.bean.getUSER_ID()>
		<cfset var local2=arguments.bean.getAMOUNT()>
		<cfset var local3=arguments.bean.getDONATION_DATE()>
		<cfset var local4=arguments.bean.getFOODDRIVE_ID()>
		<cfset var local5=arguments.bean.getPAYMENT_CONFIRM_CODE()>
		<cfset var local6=arguments.bean.getPAYMENT_CONFIRMED()>
		<cfset var local7=arguments.bean.getTRANSACTION_ID()>

		<cftransaction isolation="read_committed">
			<cfquery username="#request.username#" password="#request.password#" name="qCreate" datasource="nwharvest">
				insert into dbo.DONATIONS(USER_ID, AMOUNT, DONATION_DATE, FOODDRIVE_ID, PAYMENT_CONFIRM_CODE, PAYMENT_CONFIRMED, TRANSACTION_ID)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_INTEGER" null="#iif((local1 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_FLOAT" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local5#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local6#" cfsqltype="CF_SQL_BIT" null="#iif((local6 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local7#" cfsqltype="CF_SQL_INTEGER" null="#iif((local7 eq ""), de("yes"), de("no"))#" />
				)
				select @@Identity as pkID
			</cfquery>

		</cftransaction>

		<cfscript>
			arguments.bean.setID(qCreate.pkID);
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.Donation">
		<cfset var qUpdate="">

		<cfquery username="#request.username#" password="#request.password#" name="qUpdate" datasource="nwharvest" result="status">
			update dbo.DONATIONS
			set USER_ID = <cfqueryparam value="#arguments.bean.getUSER_ID()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.getUSER_ID() eq ""), de("yes"), de("no"))#" />,
				AMOUNT = <cfqueryparam value="#arguments.bean.getAMOUNT()#" cfsqltype="CF_SQL_FLOAT" null="#iif((arguments.bean.getAMOUNT() eq ""), de("yes"), de("no"))#" />,
				DONATION_DATE = <cfqueryparam value="#arguments.bean.getDONATION_DATE()#" cfsqltype="CF_SQL_TIMESTAMP" null="#iif((arguments.bean.getDONATION_DATE() eq ""), de("yes"), de("no"))#" />,
				FOODDRIVE_ID = <cfqueryparam value="#arguments.bean.getFOODDRIVE_ID()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.getFOODDRIVE_ID() eq ""), de("yes"), de("no"))#" />,
				PAYMENT_CONFIRM_CODE = <cfqueryparam value="#arguments.bean.getPAYMENT_CONFIRM_CODE()#" cfsqltype="CF_SQL_VARCHAR" />,
				PAYMENT_CONFIRMED = <cfqueryparam value="#arguments.bean.getPAYMENT_CONFIRMED()#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.getPAYMENT_CONFIRMED() eq ""), de("yes"), de("no"))#" />,
				TRANSACTION_ID = <cfqueryparam value="#arguments.bean.getTRANSACTION_ID()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.getTRANSACTION_ID() eq ""), de("yes"), de("no"))#" />
			where ID = <cfqueryparam value="#arguments.bean.getID()#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.Donation">
		<cfset var qDelete="">

		<cfquery username="#request.username#" password="#request.password#" name="qDelete" datasource="nwharvest" result="status">
			delete
			from dbo.DONATIONS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.getID()#" />
		</cfquery>

	</cffunction>

</cfcomponent>